/** ******
 * *******
 * *持久化存储-localStorage
 */
/**
 * @param saveKey
 * @param origin
 */
export function setStorage(saveKey = '', origin){
  let copyOrigin
  if (saveKey === '' || !origin) {
    return
  }
  if (typeof origin === 'object') {
    copyOrigin = JSON.stringify(origin)
  }
  else {
    copyOrigin = origin
  }
  localStorage.setItem(saveKey, copyOrigin)
}

/**
 * @param saveKey
 */
export function getStorage(saveKey = ''){
  if (saveKey === '') {
    return
  }
  let saveData = localStorage.getItem(saveKey)
  try {
    return JSON.parse(saveData)
  }catch (e) {
    return saveData
  }
}

export function removeStorage(saveKey){
  if (!saveKey) {
    return
  }
  localStorage.removeItem(saveKey)
}

// 清除session所有数据
export function removeAllStorage(){
  localStorage.clear()
}
